// cloudfunctions/adminLogin/index.js
const cloud = require('wx-server-sdk');
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV });

// 模拟的管理员账户
const ADMIN_USER = 'admin';
const ADMIN_PASS = 'password123';

/**
 * 云函数入口函数
 * @param {object} event - 包含从小程序端或代理云函数传来的参数
 * @returns {object} - 返回登录成功或失败的结果
 */
exports.main = async (event, context) => {
  // 参数直接从 event 对象中获取
  const { username, password } = event;

  if (username === ADMIN_USER && password === ADMIN_PASS) {
    return { success: true, message: '登录成功' };
  } else {
    return { success: false, message: '用户名或密码错误' };
  }
};